/*
 * iso9660_types.h
 */


#include <rtems/score/cpu.h>

#ifndef ISO9660_TYPES_H_
#define ISO9660_TYPES_H_

/**
 *    Bytes offsets for bi-endian 16-bit and 32-bit
 *  values
 */
#if (CPU_BIG_ENDIAN == TRUE)
#   define ISO9660_U32_OFFSET 4
#   define ISO9660_U16_OFFSET 2
#else
#   define ISO9660_U32_OFFSET 0
#   define ISO9660_U16_OFFSET 0
#endif

/** Generic pointer */
#define ISO_PTR(_ptr, _shift, _type)    ((_type *) (((uint8_t *)_ptr) + (_shift)))

/** String */
#define ISO_STR(_ptr, _shift)    ISO_PTR(_ptr, _shift, char)

/** Unsigned 8-bit value */
#define ISO_U8(_ptr, _shift)     ((uint8_t) *(((uint8_t *)_ptr) + (_shift)))

/** Signed 8-bit value */
#define ISO_S8(_ptr, _shift)     ((int8_t) *(((int8_t *)_ptr) + (_shift)))

/** Unsigned 16-bit value /!\ No endianness translation */
#define ISO_U16(_ptr, _shift)     ((uint16_t) *(((uint8_t *)_ptr) + (_shift)))

/** bi-endian unsigned 16-bit value */
#define ISO_BU16(_ptr, _shift)   ((uint16_t) *(((uint8_t *)_ptr) + (_shift) \
                                    + ISO9660_U16_OFFSET))

/** bi-endian unsigned 32-bit value */
#define ISO_BU32(_ptr, _shift)   ((uint32_t) *(((uint8_t *)_ptr) + (_shift) \
                                    + ISO9660_U32_OFFSET))

#define ISO_SET_U8(_ptr, _shift, _val) (*(((uint8_t *)_ptr) + (_shift)) = _val)


/** Extent number */
typedef uint32_t iso9660_extent_t;

/** Sector number */
typedef uint32_t iso9660_sector_t;

#endif /* ISO9660_TYPES_H_ */
